package com.llg.controller;

import com.llg.model.SpecModel;
import com.llg.model.response.DataResult;
import com.llg.model.response.PageResult;
import com.llg.model.response.ResponseResult;
import com.llg.pojo.LedSpec;
import com.llg.service.LedSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/LedSpec")
public class LedSpecController {

    @Autowired
    private LedSpecService specService;

    //根据品牌id查询该品牌所有型号
    @GetMapping("/findByBrandId")
    public PageResult<SpecModel> findByBrandId(Integer bid){
        return specService.findByBrandId(bid);
    }

    //搜索并分页查询
    @PostMapping("/findList")
    public PageResult<SpecModel> findPage(Integer currentPage, Integer pageSize, @RequestBody LedSpec ledSpec){
        return specService.findList(currentPage, pageSize, ledSpec);
    }

    //根据id查询
    @GetMapping("/{id}")
    public DataResult<SpecModel> findById(@PathVariable("id") Integer id){
        return specService.findById(id);
    }

    //通过接收卡id查询所有未与该接收卡对应的led型号
    @GetMapping("/findByRid")
    public PageResult<SpecModel> findByRid(int rid){
        return specService.findByRid(rid);
    }

    //新增
    @PostMapping("/add")
    public DataResult<SpecModel> add(@RequestBody SpecModel specModel){
        return specService.save(specModel);
    }

    //修改
    @PostMapping("/update")
    public ResponseResult update(@RequestBody SpecModel specModel){
        return specService.update(specModel);
    }

    //删除
    @GetMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return specService.delete(id);
    }
}
